package org.benjamin.lending.controller;

import org.benjamin.lending.domain.entity.BorrowInfo;
import org.benjamin.lending.service.BorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

@Controller
@RequestMapping("borrow")
public class BorrowController {
	
	@Autowired
	private BorrowService borrowService;
	
	@RequestMapping(value = "index")
	public String index() {
		return "";
	}
	
	/**
	 * 查看借款标详情
	 * @return
	 */
	@GetMapping(value = "details/{borrowId}")
	public ModelAndView details(@PathVariable("borrowId")Integer borrowId) {
		ModelAndView modelAndView = new ModelAndView("borrow/details");
		BorrowInfo borrowInfo = this.borrowService.findByBorrowEntity(borrowId);
		modelAndView.addObject("borrowInfo",borrowInfo);
		return modelAndView;
	}
	
	@GetMapping(value = "tender")
	public ModelAndView tender(Integer borrowId) {
		ModelAndView modelAndView = new ModelAndView(new RedirectView("details/"+borrowId,false));
		return modelAndView;
	}

}
